home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d14 / eyewatch.arc / EYES.OLD < prev    next >
Text File  |  1990-09-07  |  8KB  |  306 lines

  1. /********************************************************************\
  2.  EyeWatch -- Cursor Tracking Program.
  3.  
  4.  Written By:  Paul L. Yao & Malcolm Austin
  5. \********************************************************************/
  6.  
  7.  
  8. #include "windows.h"
  9. #include <math.h>
  10.  
  11.  
  12. static  HANDLE  hInst;
  13. static  HWND  hWnd;
  14. static  HWND  hWnd1;
  15. static  HWND  hWnd2;
  16.  
  17. POINT pt;
  18. POINT ptOld;
  19.  
  20. RECT  rOldEye1;
  21. RECT  rOldEye2;
  22.  
  23. HBRUSH hWhiteBrush;
  24. HBRUSH hBlackBrush;
  25. HPEN   hWhitePen;
  26.  
  27. char   acMainWndProc[] = "MainEyes";
  28. char   acEyeWndProc[]  = "PlyEyes";
  29.  
  30. long FAR PASCAL MainWinProc (HWND, unsigned, WORD, LONG);
  31. long FAR PASCAL EyeWinProc (HWND, unsigned, WORD, LONG);
  32.  
  33.  
  34. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  35. HANDLE hInstance, hPrevInstance;
  36. LPSTR  lpszCmdLine;
  37. int    cmdShow;
  38. {
  39.   MSG   msg;
  40.   RECT  r;
  41.  
  42.   if (!hPrevInstance)
  43.   {
  44.     WNDCLASS   rClass;
  45.  
  46.     rClass.lpszClassName = acMainWndProc;
  47.     rClass.hInstance     = hInstance;
  48.     rClass.lpfnWndProc   = MainWinProc;
  49.     rClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
  50.     rClass.hIcon         = NULL;
  51.     rClass.lpszMenuName  = NULL;
  52.     rClass.hbrBackground = hWhiteBrush;
  53.     rClass.style         = CS_HREDRAW|CS_VREDRAW;
  54.     rClass.cbClsExtra    = 0;
  55.     rClass.cbWndExtra    = 0;
  56.  
  57.     RegisterClass(&rClass);
  58.  
  59.     rClass.lpszClassName = acEyeWndProc;
  60.     rClass.hInstance     = hInstance;
  61.     rClass.lpfnWndProc   = EyeWinProc;
  62.     rClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
  63.     rClass.hIcon         = NULL;
  64.     rClass.lpszMenuName  = NULL;
  65.     rClass.hbrBackground = hWhiteBrush;
  66.     rClass.style         = CS_HREDRAW|CS_VREDRAW;
  67.     rClass.cbClsExtra    = 0;
  68.     rClass.cbWndExtra    = 0;
  69.  
  70.     RegisterClass(&rClass);
  71.  
  72.   }
  73.   else ;
  74.  
  75.   hInst = hInstance;
  76.  
  77.   hWhiteBrush = GetStockObject (WHITE_BRUSH);
  78.   hBlackBrush = GetStockObject (BLACK_BRUSH);
  79.   hWhitePen   = GetStockObject (WHITE_PEN);
  80.  
  81.   hWnd = CreateWindow(acMainWndProc,
  82.               "Eyes",
  83.                       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  84.                       CW_USEDEFAULT,
  85.                       0,
  86.                       CW_USEDEFAULT,
  87.                       0,
  88.               NULL,
  89.               NULL,
  90.               hInstance,
  91.               NULL
  92.                      );
  93.  
  94.   GetClientRect (hWnd, &r);
  95.   hWnd1 = CreateWindow(acEyeWndProc,
  96.                NULL,
  97.                WS_CHILDWINDOW | WS_VISIBLE,
  98.                0,
  99.                0,
  100.                r.bottom,
  101.                r.right/2,
  102.                hWnd,
  103.                1,
  104.            hInstance,
  105.            NULL
  106.               );
  107.  
  108.   hWnd2 = CreateWindow(acEyeWndProc,
  109.                NULL,
  110.                WS_CHILDWINDOW | WS_VISIBLE,
  111.                r.right/2+1,
  112.                0,
  113.                r.bottom,
  114.                r.right/2,
  115.                hWnd,
  116.                2,
  117.            hInstance,
  118.            NULL
  119.               );
  120.  
  121.   ShowWindow(hWnd, cmdShow);
  122.  
  123.   SetTimer (hWnd, 1, 100, NULL);
  124.  
  125.   while (GetMessage(&msg, NULL, 0, 0))
  126.   {
  127.     TranslateMessage(&msg);
  128.     DispatchMessage(&msg);
  129.   }
  130.  
  131.   exit(msg.wParam);
  132.  
  133. }
  134.  
  135. /********************************************************************\
  136. \********************************************************************/
  137. long FAR PASCAL EyeWinProc (hWnd, identifier, wParam, lParam)
  138.   HWND       hWnd;
  139.   unsigned   identifier;
  140.   WORD       wParam;
  141.   LONG       lParam;
  142. {
  143.   HDC hDC;
  144.   PAINTSTRUCT ps;
  145.   RECT r;
  146.   POINT pt2;
  147.   int   xShift;
  148.   int   yShift;
  149.   double dX;
  150.   double dY;
  151.   double dT;
  152.   char ac[100];
  153.  
  154.   switch (identifier)
  155.   {
  156.     case WM_ERASEBKGND:
  157.         GetClientRect (hWnd, &r);
  158.         FillRect ((HDC)wParam, &r, hWhiteBrush);
  159.  
  160.         /* Set up mapping mode. */
  161.         SetMapMode ((HDC)wParam, MM_ISOTROPIC);
  162.         SetViewportOrg ((HDC)wParam, r.right/2, r.bottom/2);
  163.         SetWindowExt ((HDC)wParam, 100, 100);
  164.         SetViewportExt ((HDC)wParam, r.right, r.bottom);
  165.  
  166.         /* Draw Outline of Eye.  */
  167.         Ellipse ((HDC)wParam, -49, 42, 49, -42);
  168.         break;
  169.  
  170.     case WM_PAINT:
  171.         hDC = BeginPaint (hWnd, &ps);
  172.         GetClientRect (hWnd, &r);
  173.         SetMapMode (hDC, MM_ISOTROPIC);
  174.         SetViewportOrg (hDC, r.right/2, r.bottom/2);
  175.         SetWindowExt (hDC, 100, 100);
  176.         SetViewportExt (hDC, r.right, r.bottom);
  177.  
  178.         /* Use a white pen to ease erasing overhead.  */
  179.         SelectObject (hDC, hWhitePen);
  180.  
  181.         /* Erase old eye.  */
  182.         if (hWnd == hWnd1)
  183.             Ellipse (hDC,
  184.                      rOldEye1.left,
  185.                      rOldEye1.top,
  186.                      rOldEye1.right,
  187.                      rOldEye1.bottom);
  188.         else
  189.             Ellipse (hDC,
  190.                      rOldEye2.left,
  191.                      rOldEye2.top,
  192.                      rOldEye2.right,
  193.                      rOldEye2.bottom);
  194.  
  195.         /* Determine location of iris.  */
  196.         pt2 = pt;
  197.         ScreenToClient (hWnd, &pt2);
  198.         DPtoLP (hDC, &pt2, 1);
  199.  
  200.         dX = (double) pt2.x;
  201.         dY = (double) pt2.y;
  202.         dT = sqrt ((dX*dX)+(dY*dY));
  203.  
  204.         xShift = (int) ( (20<dT) ? (dX * 20/dT) : dX );
  205.         yShift = (int) ( (20<dT) ? (dY * 20/dT) : dY );
  206.  
  207.         /* Draw iris.  */
  208.         SelectObject (hDC, hBlackBrush);
  209.  
  210.         Ellipse (hDC, -20+xShift, 20+yShift, 20+xShift, -20+yShift);
  211.         if (hWnd == hWnd1) {
  212.             rOldEye1.left   = -20+xShift;
  213.             rOldEye1.top    =  20+yShift;
  214.             rOldEye1.right  =  20+xShift;
  215.             rOldEye1.bottom = -20+yShift;
  216.             }
  217.         else {
  218.             rOldEye2.left   = -20+xShift;
  219.             rOldEye2.top    =  20+yShift;
  220.             rOldEye2.right  =  20+xShift;
  221.             rOldEye2.bottom = -20+yShift;
  222.             }
  223.  
  224.         EndPaint (hWnd, &ps);
  225.         break;
  226.  
  227.     default:
  228.       return(DefWindowProc(hWnd, identifier, wParam, lParam));
  229.       break;
  230.   }
  231.   return(0L);
  232. }
  233.  
  234. /********************************************************************\
  235. \********************************************************************/
  236. long FAR PASCAL MainWinProc(hWnd, identifier, wParam, lParam)
  237.   HWND       hWnd;
  238.   unsigned   identifier;
  239.   WORD       wParam;
  240.   LONG       lParam;
  241. {
  242.   HDC          hDC;
  243.   PAINTSTRUCT ps;
  244.   RECT          r;
  245.  
  246.   switch (identifier)
  247.   {
  248.     case WM_CLOSE:
  249.         DestroyWindow (hWnd);
  250.         break;
  251.  
  252.     case WM_DESTROY:
  253.         PostQuitMessage(0);
  254.         break;
  255.  
  256.     case WM_PAINT:
  257.     hDC = BeginPaint (hWnd, &ps);
  258.     if (IsIconic (hWnd)) {
  259.         GetClientRect (hWnd, &r);
  260.         Rectangle (hDC, 0, 0, r.right, r.bottom);
  261.         }
  262.     EndPaint (hWnd, &ps);
  263.     break;
  264.  
  265.     case WM_PAINTICON:
  266.     InvalidateRect (hWnd1, NULL, FALSE);
  267.     UpdateWindow (hWnd1);
  268.     UpdateWindow (hWnd2);
  269.     break;
  270.  
  271.     case WM_ICONERASEBKGND:
  272.     hDC = GetDC (hWnd1);
  273.     PostMessage (hWnd1, WM_ERASEBKGND, (WORD)hDC, 0L);
  274.     ReleaseDC (hWnd, hDC);
  275.     hDC = GetDC (hWnd2);
  276.     PostMessage (hWnd2, WM_ERASEBKGND, (WORD)hDC, 0L);
  277.     ReleaseDC (hWnd, hDC);
  278.     break;
  279.  
  280.     case WM_SIZE:
  281.         MoveWindow(hWnd1, 0, 0, LOWORD(lParam)/2, HIWORD(lParam), TRUE);
  282.         MoveWindow(hWnd2, LOWORD(lParam)/2, 0, LOWORD(lParam)/2, HIWORD(lParam), TRUE);
  283.         break;
  284.  
  285.     case WM_TIMER:
  286.         GetCursorPos (&pt);
  287.         if (ptOld.x != pt.x || ptOld.y != pt.y ) {
  288.             InvalidateRect (hWnd1, NULL, FALSE);
  289.             InvalidateRect (hWnd2, NULL, FALSE);
  290.         if (IsIconic (hWnd)) {
  291.         PostMessage (hWnd1, WM_PAINT, 0, 0L);
  292.         PostMessage (hWnd2, WM_PAINT, 0, 0L);
  293.         }
  294.             ptOld.x = pt.x;
  295.             ptOld.y = pt.y;
  296.             }
  297.         break;
  298.  
  299.     default:
  300.       return(DefWindowProc(hWnd, identifier, wParam, lParam));
  301.       break;
  302.   }
  303.   return(0L);
  304. }
  305. 
  306.